
/**
 * Given an array of strings strs, group the anagrams together. You can return the
 * answer in any order.
 * <p>
 * An Anagram is a word or phrase formed by rearranging the letters of a
 * different word or phrase, typically using all the original letters exactly once.
 * <p>
 * <p>
 * Example 1:
 * Input: strs = ["eat","tea","tan","ate","nat","bat"]
 * Output: [["bat"],["nat","tan"],["ate","eat","tea"]]
 * <p>
 * Example 2:
 * Input: strs = [""]
 * Output: [[""]]
 * <p>
 * Example 3:
 * Input: strs = ["a"]
 * Output: [["a"]]
 * <p>
 * <p>
 * Constraints:
 * <p>
 * <p>
 * 1 <= strs.length <= 10⁴
 * 0 <= strs[i].length <= 100
 * strs[i] consists of lowercase English letters.
 * <p>
 * <p>
 * Related Topics 数组 哈希表 字符串 排序 👍 1313 👎 0
 */


package com.xixi.basicAlgroithms.hash;

import java.util.*;

public class ID00049GroupAnagrams {
    public static void main(String[] args) {
        Solution solution = new ID00049GroupAnagrams().new Solution();
    }


    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public List<List<String>> groupAnagrams(String[] strs) {

            Map<String, List<String>> mapList = new HashMap<>();

            for (int i = 0; i < strs.length; i++) {
                putInMapList(strs[i], mapList);
            }

            List<List<String>> res = new ArrayList<>();
            for (List<String> anagramsList : mapList.values()) {

            }
            res.addAll(mapList.values());

            return res;
        }

        public void putInMapList(String word, Map<String, List<String>> mapList) {

            char[] wordChar = word.toCharArray();
            Arrays.sort(wordChar);

            String keyStr = new String(wordChar);
            List<String> anagramsList;
            if (!mapList.containsKey(keyStr)) {
                anagramsList = new ArrayList<>();
            } else {
                anagramsList = mapList.get(keyStr);
            }
            anagramsList.add(word);
            mapList.put(keyStr, anagramsList);

        }


    }
//leetcode submit region end(Prohibit modification and deletion)


}